package com.kingmed.kmss.framework.feign.client.auth;

import cn.hutool.http.HttpStatus;
import com.kingmed.kmss.common.dto.api.resp.admin.TokenAuthUserVo;
import com.kingmed.kmss.common.dto.auth.CustomMessageReq;
import com.kingmed.kmss.common.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CommonAuthFeignFacade {

    @Autowired
    private CommonAuthFeignService remoteFeignService;

    @Async("defaultThreadPoolExecutor")
    public String sendOaMsg(CustomMessageReq customMessageReq) {
        CommonResponse<?> response = remoteFeignService.sendOaMsg(customMessageReq);
        log.info("调用auth工程oa消息发送接口成功，出参：{}", response);
        if (HttpStatus.HTTP_OK == response.getCode()) {
            return response.getMessage();
        }
        return null;
    }

    public TokenAuthUserVo checkToken(String token) {
        CommonResponse<TokenAuthUserVo> response = remoteFeignService.checkToken(token);
        log.info("调用auth工程成功，出参：{}", response);
        if (HttpStatus.HTTP_OK == response.getCode()) {
            return response.getData();
        }
        return null;
    }

}
